package org.tang.springcloudvv.util;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/*
 * tangfuzhong
 * 解析异常的消息
 */
public class ExceptionUtil {

	public static String getExceptionMessage(Throwable e) {
		if (e == null)
		{
			return "throwableIsNull";
		}
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		PrintStream pout = new PrintStream(out);
		e.printStackTrace(pout);
		String ret = new String(out.toByteArray());
		pout.close();
		try {
			out.close();
		} catch (Exception ex) {
		}
		return ret;
	}
	
	public static String getExceptionMessage(Throwable e,int length) {
		String mString = getExceptionMessage(e);
		if (mString != null && mString.length()>(length+1))
		{
			mString = mString.substring(0,length);
		}
		return mString;
	}
	
}
